SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


IF OBJECT_ID('dbo.[Templete]', N'U') IS NOT NULL
DROP TABLE [dbo].[Templete]
GO

/****** Object:  Table [dbo].[Templete]    Script Date: 4/29/2014 2:18:08 PM ******/
CREATE TABLE [dbo].[Templete](
	[Id] [uniqueidentifier] NOT NULL,
	[Name] [nvarchar](256) NOT NULL,
	[Value] [nvarchar](4000) NOT NULL,
CONSTRAINT [PK_Templete] PRIMARY KEY CLUSTERED 
	([Id] ASC)
	WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
	) ON [PRIMARY]
GO


IF OBJECT_ID('dbo.[TempleteView]', 'V') IS NOT NULL
DROP VIEW [dbo].[TempleteView]
GO

/****** Object:  View [dbo].[TempleteView]    Script Date: 4/29/2014 2:18:08 PM ******/
CREATE VIEW [dbo].[TempleteView]
AS
	SELECT
	T.[Id]
	,T.[Name]
	,T.[Value]
	From Templete T

GO
SET ANSI_PADDING OFF 
GO


IF OBJECT_ID('dbo.[usp_TempleteInsert]', N'P') IS NOT NULL
DROP PROCEDURE[dbo].[usp_TempleteInsert]
GO

/****** Object:  StoredProcedure [dbo].[usp_TempleteInsert]    Script Date: 4/29/2014 2:18:08 PM ******/
CREATE PROC [dbo].[usp_TempleteInsert]
	@Id  [uniqueidentifier]
	,@Name [nvarchar](256)
	,@Value [nvarchar](4000) 

AS
	SET NOCOUNT ON 
	SET XACT_ABORT ON

	BEGIN TRAN

	INSERT INTO [dbo].[Templete] ([Id], [Name], [Value])
	SELECT @Id, @Name, @Value

	COMMIT;

	SELECT
	T.[Id]
	,T.[Name]
	,T.[Value]
	From Templete T
	WHERE T.[Id] = @Id

GO


IF OBJECT_ID('dbo.[usp_TempleteUpdate]', N'P') IS NOT NULL
DROP PROCEDURE[dbo].[usp_TempleteUpdate]
GO

/****** Object:  StoredProcedure [dbo].[usp_TempleteUpdate]    Script Date: 4/29/2014 2:18:08 PM ******/
CREATE PROC [dbo].[usp_TempleteUpdate]
	@Id  [uniqueidentifier]
	,@Name [nvarchar](256)
	,@Value [nvarchar](4000) 

AS
	SET NOCOUNT ON 
	SET XACT_ABORT ON

	BEGIN TRAN

	UPDATE [dbo].[Templete]
	SET [Id] = @Id, [Name] = @Name, [Value] = @Value	WHERE [Id] = @Id


	COMMIT;

	SELECT
	T.[Id]
	,T.[Name]
	,T.[Value]
	From Templete T
	WHERE T.[Id] = @Id

GO


IF OBJECT_ID('dbo.[usp_TempleteDelete]', N'P') IS NOT NULL
DROP PROCEDURE[dbo].[usp_TempleteDelete]
GO

/****** Object:  StoredProcedure [dbo].[usp_TempleteDelete]    Script Date: 4/29/2014 2:18:08 PM ******/
CREATE PROC [dbo].[usp_TempleteDelete]
	@Id uniqueidentifier
AS
SET NOCOUNT ON
SET XACT_ABORT ON

BEGIN TRAN
	DELETE FROM [dbo].[Templete] WHERE  [Id] = @Id
COMMIT;
GO

